package controller

import (
	"net/http"
	pb "proto"

	"github.com/gin-gonic/gin"
)

type BattleController struct {
	battleClient pb.BattleServiceClient
}

func NewBattleController(battleClient pb.BattleServiceClient) *BattleController {
	return &BattleController{
		battleClient: battleClient,
	}
}

func (bc *BattleController) GetBattleResult(c *gin.Context) {
	battleID := c.Param("battleId")

	// 调用battle-server获取结果
	resp, err := bc.battleClient.GetBattleResult(c, &pb.BattleResultRequest{
		BattleId: battleID,
	})

	if err != nil {
		c.JSON(http.StatusInternalServerError, gin.H{
			"success": false,
			"message": "Failed to get battle result",
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"success": true,
		"result":  resp.Result,
	})
}
